#ifndef __ECC_H
#define __ECC_H

#include "mpi.h"

struct ecc_sm2_parms {
    const char*  desc;     /* Description of the curve.  */
    unsigned int nbits;    /* Number of bits.  */
    unsigned int fips : 1; /* True if this is a FIPS140-2
                              approved curve */

    /* The model describing this curve.  This is mainly used
     * to select the group equation.
     */
    enum gcry_mpi_ec_models model;

    /* The actual ECC dialect used.  This is used for curve
     * specific optimizations and to select encodings etc.
     */
    enum ecc_dialects dialect;

    const char* p;          /* The prime defining the field.  */
    const char *a, *b;      /* The coefficients.  For Twisted Edwards
                             * Curves b is used for d.  For Montgomery
                             * Curves (a,b) has ((A-2)/4,B^-1).
                             */
    const char*  n;         /* The order of the base point.  */
    const char * g_x, *g_y; /* Base point.  */
    unsigned int h;         /* Cofactor.  */
};

#define SM2_PRIVKEY_LEN (32)
#define SM2_PUBKEY_LEN  (64)

struct ec_key_st {
    MPI_POINT pub;
    MPI       priv;
};
typedef struct ec_key_st EC_KEY;

typedef struct gcry_mpi_point EC_POINT;

int sm2_ec_ctx_init(void);

void sm2_ec_ctx_deinit(void);

EC_KEY* ec_key_new(void);

void ec_key_free(EC_KEY* key);

int ec_gen_keypair(EC_KEY* key);

int ec_check_pubkey(EC_KEY* key);

int ec_key_to_buf(EC_KEY* key, unsigned char pubkey[SM2_PUBKEY_LEN],
                  unsigned char privkey[SM2_PRIVKEY_LEN]);

#endif  // __ECC_H